<?php

class Default_IndexController extends Zend_Controller_Action
{

    public function init()
    {
         $options = array(
        		'layout'=>'layout',
        		'layoutPath'=>LAYOUT_PATH."/default"
        );
        Zend_Layout::startMvc($options);
        $this->view->headLink()->appendStylesheet(TEMPLATE_URL.'/min/g=css-default-index');
        $this->view->headScript()->appendFile(TEMPLATE_URL.'/min/g=js-default-index');
    }

    public function indexAction()
    {
        
        //$this->view->headScript()->appendFile(TEMPLATE_URL.'/assets/responsiveslides/responsiveslides.min.js');
        
        $mApp = new Application_Model_App();
        $this->view->new_app = $mApp->getTopNewIndex();
        
    }

    public function topdownloadAction()
    {
        // action body
    }

    public function detailAction()
    {
        $this->view->headScript()->appendFile(TEMPLATE_URL.'/min/g=js-default-app-detail?12a');
        $this->view->headLink()->appendStylesheet(TEMPLATE_URL.'/min/g=css-default-app-detail?a23');
        $id = $this->getRequest()->getParam('id');
        
        $mApp = new Application_Model_App();
        $mVers = new Application_Model_Appversion();
        $mScr = new Application_Model_Screenshot();
        
        //thong tin chi tiet app
        $this->view->app_info = $mApp->getByID($id);
        
        //thông tin apk
        $this->view->app_vers = $mVers->getByAppId($id);
        
        //ảnh màn hình
        $this->view->app_scr = $mScr->getByAppID($id);
        
        //ứng dụng liên quan
        $this->view->new_app = $mApp->getTopNewIndex();
        
        //lay thông tin server
        $mOption = new Application_Model_Option();
        $server = $mOption->getByName('ftp_server');
        $server = json_decode($server,true);
        
        
        
    }

    public function downloadAction()
    {
        $this->_helper->layout()->disableLayout();
        
        $name = "com.ifunsoft.blockarrange";
        $version="1.0";
        
        $func = new NVL_Functions();
        
        $key = $func->RandomString(20);
        $key = sha1($key);
        //$contents = file_get_contents('http://ifs.890m.com/gettext.php?key='.$key);
        //var_dump($contents);
        
        $en_code = $func->ifs_encode('113.163.66.165');
        echo $en_code."<br>";
        var_dump($func->ifs_decode($en_code));
        
        //echo $contents;
        header('Location: http://ifs.890m.com/download.php?name=com.ifunsoft.blockarrange&version=1.0&code='.$en_code);
        
        
        $cookie_name = "new";
        $cookie_value = "John Doe";
        setcookie($cookie_name, $cookie_value, time() + 600, "/"); // 86400 = 1 day
        //var_dump($_SESSION);
    }


}







